Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/di class #260

Closed
wants to merge 4 commits into from
Closed

Feat/di class #260

wants to merge 4 commits into from

Conversation

woile
Copy link
Member

@woile woile commented Dec 30, 2024

pydantic model as ConsumerRecord[..., V[

Add support for pydantic as a generic in ConsumerRecord:

class Customer(BaseModel):
    id: int

@stream_engine.stream("local--kstreams")
async def stream(cr: ConsumerRecord[str, Customer]):
    assert cr.value.id == 1

This helps with autocomplete and with faster time to market, because users don't have to manually convert

why not dataclasses?

A simple dataclass is ok to cast, but if we have nested dataclasses, it becomes a problem I haven't been able to solve (maybe in the future?). While on pydantic it just works.

E.g:

class Address:
     street: str

class Customer:
    name: str
    addr: Address

data = {
    "name": "jon",
    "addr": {
        "street": "av siempre viva"
    }
}
r = Consumer(**data)
assert isinstance(r.addr, Address) is True
# assert FAILS

@woile woile requested a review from marcosschroh December 30, 2024 17:36
Copy link
Contributor

github-actions bot commented Dec 30, 2024

PR Preview Action v1.4.8
Preview removed because the pull request was closed.
2025-01-06 13:22 UTC

Copy link

codecov bot commented Dec 30, 2024

Codecov Report

Attention: Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.84%. Comparing base (e8d4b7e) to head (cd50778).

Files with missing lines Patch % Lines
kstreams/middleware/udf_middleware.py 95.23% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #260      +/-   ##
==========================================
+ Coverage   95.68%   95.84%   +0.16%     
==========================================
  Files          24       24              
  Lines         973      987      +14     
==========================================
+ Hits          931      946      +15     
+ Misses         42       41       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@woile
Copy link
Member Author

woile commented Dec 30, 2024

I think we can still merge.
There's only a regression on startup time:

test_startup_and_inject_all (0003_d75800b) - Field 'mean' has failed PercentageRegressionCheck: 14.958420546 > 10.000000000

@woile
Copy link
Member Author

woile commented Jan 6, 2025

Discussed with Marcos, we agreed not adding pydantic to kstreams to keep the project lightweight

@woile woile closed this Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant